/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.teste;

import br.com.modelo.Autor;
import java.util.Scanner;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

/**
 *
 * @author egberto
 */
public class InsereAutorComJPA {
    public static void main(String args[]){
        EntityManagerFactory factory = Persistence.createEntityManagerFactory("default");
        EntityManager manager = factory.createEntityManager();
        
        Autor autor = new Autor();
        
        Scanner entrada = new Scanner(System.in);
        
        System.out.println("Digite o nome do autor: ");
        autor.setNome(entrada.nextLine());
        
        manager.getTransaction().begin();
        manager.persist(autor);
        manager.getTransaction().commit();
        
        factory.close();
    }
    
}
